
class SyncFlag {
	boolean flag;
	boolean someoneWaiting = false;
	synchronized void get(String na) {		
		if (!someoneWaiting) {
			try {
				//System.out.println("Calling wait: " + na);
				someoneWaiting = true;
				wait();
				}
			catch(Exception e) {
				e.printStackTrace();
				}
			}
		else {
		    someoneWaiting = false;
		    //System.out.println("Calling notifyAll: " + na);
		    notifyAll();			
			}
    
  		}
	
	synchronized void release() {
		someoneWaiting = false;
		notifyAll();
		}
	}